package fi.tikesos.validator.jena.rdfa;

import org.xml.sax.SAXParseException;

import com.hp.hpl.jena.rdf.model.RDFErrorHandler;

public class XHTMLRDFaErrorHandler implements RDFErrorHandler{
	private boolean error,warning;
	private String errorMessage,errorType,warningMessage;
	
	public XHTMLRDFaErrorHandler() {
		error = false;
		warning = false;
	}
	
	public boolean isError() {
		return error;
	}

	public boolean isWarning() {
		return warning;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public String getErrorType() {
		return errorType;
	}

	public String getWarningMessage() {
		return warningMessage;
	}

	private void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	private void setErrorType(String errorType) {
		this.errorType = errorType;
	}

	private void setWarningMessage(String warningMessage) {
		this.warningMessage = warningMessage;
	}

	@Override
	public void warning(Exception e) {
		warning = true;
		setWarningMessage(e.getMessage());
	}

	@Override
	public void error(Exception e) {
		if (e instanceof SAXParseException) {
			setErrorType("XHTML error");
			setErrorMessage(""+((SAXParseException) e).getLineNumber()+":"+((SAXParseException) e).getColumnNumber()+" "+((SAXParseException) e).getMessage());
		} else setErrorMessage(e.getMessage());
		error = true;
		setErrorType("Error");
	}

	@Override
	public void fatalError(Exception e) {
		error = true;
		if (e instanceof SAXParseException) {
			setErrorType("XHTML error");
			setErrorMessage(""+((SAXParseException) e).getLineNumber()+":"+((SAXParseException) e).getColumnNumber()+". "+((SAXParseException) e).getMessage());
		} else setErrorMessage(e.getMessage());
		
	}
	
	


}
